﻿using System.Collections.Generic;

namespace NpcFramework
{
    public class NpcDataManager
    {
        private Dictionary<int, NpcData> _npcDatas;
        public static int MainCharacterId = -666;
        public static int SpecialId = -667;
        public NpcDataManager(int capacity = 50)
        {
            _npcDatas = new Dictionary<int, NpcData>(capacity);    
        }


        public void AddNpcData(int id)
        {
            if (!_npcDatas.ContainsKey(id))
            {
                _npcDatas[id] = new NpcData(id);
            }
        }

        public void RemoveNpcData(int id, bool isDeleteData)
        {
            if (isDeleteData)
            {
                if (_npcDatas.ContainsKey(id))
                {
                    _npcDatas.Remove(id);
                }
            }
        }

        public NpcData GetNpcData(int id)
        {
            NpcData npcData;
            if (_npcDatas.TryGetValue(id,out npcData))
            {
                return npcData;
            }
            return null;
        }

        public bool IsMainCharactor(int id)
        {
            return id == MainCharacterId || id == SpecialId;
        }

        public void Dispose()
        {
            if (_npcDatas != null)
            {
                _npcDatas.Clear();
                _npcDatas = null;
            }
        }
    }
}
